# coding:utf-8
# @Time : 2021/5/10 18:24 
# @Author : minuy
# @File : number_tool.py


def is_number(s):
    try:
        float(s)
        return True
    except ValueError:
        pass

    try:
        import unicodedata
        unicodedata.numeric(s)
        return True
    except (TypeError, ValueError):
        pass

    return False


def decimal_digits(val: float):
    """
    判断小数位数
    :param val:
    :return:
    """
    val_str = str(val)
    digits_location = val_str.find('.')
    if digits_location:
        return len(val_str[digits_location + 1:])


def is_price(s):
    """
    判断是否是价格
    :param s:
    :return:
    """
    try:
        s = float(s)
        if decimal_digits(s) <= 2:
            return True
    except ValueError:
        pass

    try:
        import unicodedata
        unicodedata.numeric(s)
        return True
    except (TypeError, ValueError):
        pass

    return False
